package com.ruoyi.web.controller.record;

import java.util.List;

import com.ruoyi.record.service.impl.WordRecordCommonService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.record.domain.WordStudyRecord;
import com.ruoyi.record.service.IWordStudyRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单词学习记录Controller
 *
 * @author ruoyi
 * @date 2025-07-04
 */
@RestController
@RequestMapping("/record/study_record")
public class WordStudyRecordController extends BaseController
{
    @Autowired
    private IWordStudyRecordService wordStudyRecordService;

    @Autowired
    private WordRecordCommonService recordCommonService;


    /**
     * 查询单词学习记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WordStudyRecord wordStudyRecord)
    {
        WordStudyRecord record = recordCommonService.selectList(wordStudyRecord);
        startPage();
        List<WordStudyRecord> list = wordStudyRecordService.selectWordStudyRecordList(record);
        return getDataTable(list);
    }

    @GetMapping("/listAll")
    public AjaxResult listAll(WordStudyRecord wordStudyRecord)
    {
        List<WordStudyRecord> list = wordStudyRecordService.selectWordStudyRecordList(wordStudyRecord);
        return AjaxResult.success(list);
    }

    @GetMapping("/list_ByUser")
    public TableDataInfo listByUser(WordStudyRecord wordStudyRecord)
    {
        WordStudyRecord record = recordCommonService.selectList(wordStudyRecord);
        startPage();
        List<WordStudyRecord> list = wordStudyRecordService.selectWordStudyRecordListByUser(record);
        return getDataTable(list);
    }

    @GetMapping("/write_list_ByUser")
    public TableDataInfo wirteListByUser(WordStudyRecord wordStudyRecord)
    {
        WordStudyRecord record = recordCommonService.selectList(wordStudyRecord);
        startPage();
        List<WordStudyRecord> list = wordStudyRecordService.selectWordWriteRecordListByUser(record);
        return getDataTable(list);
    }

    //查询所有汉译英的数据
    @GetMapping("/list_write_all")
    public TableDataInfo list_write_all(WordStudyRecord wordStudyRecord)
    {
        startPage();
        List<WordStudyRecord> list = wordStudyRecordService.selectWordStudyRecordWriteList(wordStudyRecord);
        return getDataTable(list);
    }

    /**
     * 导出单词学习记录列表
     */
//    @PreAuthorize("@ss.hasPermi('record:study_record:export')")
    @Log(title = "单词学习记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WordStudyRecord wordStudyRecord)
    {
        List<WordStudyRecord> list = wordStudyRecordService.selectWordStudyRecordList(wordStudyRecord);
        ExcelUtil<WordStudyRecord> util = new ExcelUtil<WordStudyRecord>(WordStudyRecord.class);
        util.exportExcel(response, list, "单词学习记录数据");
    }

    /**
     * 获取单词学习记录详细信息
     */
//    @PreAuthorize("@ss.hasPermi('record:study_record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(wordStudyRecordService.selectWordStudyRecordById(id));
    }

    /**
     * 新增单词学习记录
     */
//    @PreAuthorize("@ss.hasPermi('record:study_record:add')")
    @Log(title = "单词学习记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WordStudyRecord wordStudyRecord)
    {
        return toAjax(wordStudyRecordService.insertWordStudyRecord(wordStudyRecord));
    }

    /**
     * 修改单词学习记录
     */
//    @PreAuthorize("@ss.hasPermi('record:study_record:edit')")
    @Log(title = "单词学习记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WordStudyRecord wordStudyRecord)
    {
        return toAjax(wordStudyRecordService.updateWordStudyRecord(wordStudyRecord));
    }

    /**
     * 删除单词学习记录
     */
//    @PreAuthorize("@ss.hasPermi('record:study_record:remove')")
    @Log(title = "单词学习记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(wordStudyRecordService.deleteWordStudyRecordByIds(ids));
    }
}
